
#include "Allegro_initialize.h"

SETUP_STATUS init_alleg( Allegro_resources &resources)
{

	if (!al_init())
	{
		return ALLEGRO_INITIALIZATION_ERROR;
	}

	resources._display = al_create_display(screen_width, screen_height);

	if (!resources._display)
	{
		return DISPLAY_SETUP_ERROR;	
	}

	if(!al_install_keyboard())
	{
		return KEYBOARD_SETUP_ERROR;
	}

	if(!al_init_primitives_addon())
	{
		return PRIMITIVES_ADDON_SETUP_ERROR;
	}

	resources._timer = al_create_timer(1.0 / FPS);

	if(!resources._timer)
	{
		al_destroy_display(resources._display);
		return TIMER_SETUP_ERROR;	
	}
	
	resources._event_queue = al_create_event_queue();

	if(!resources._event_queue) 
	{
		al_destroy_display(resources._display);
		return EVENT_QUEUE_SETUP_ERROR;
	}

	al_register_event_source(resources._event_queue, al_get_keyboard_event_source());
	al_register_event_source(resources._event_queue, al_get_display_event_source(resources._display));
	al_register_event_source(resources._event_queue, al_get_timer_event_source(resources._timer));
	


	return SETUP_SUCCESFULL;

}

string create_error_message( SETUP_STATUS status)
{

	switch (status)
	{
		case ALLEGRO_INITIALIZATION_ERROR:
			return "Error with initializing Allegro";
			break;
		case DISPLAY_SETUP_ERROR:
			return "Error with creating display";
			break;
		case PRIMITIVES_ADDON_SETUP_ERROR:
			return "Error with initializing Primmitives addon";
			break;
		case KEYBOARD_SETUP_ERROR:
			return "Error with setting up keyboard";
			break;
		case TIMER_SETUP_ERROR:
			return "Error with setting up timer";
			break;
		case EVENT_QUEUE_SETUP_ERROR:
			return "Error with setting up event queue";
			break;


	}
}

void display_setup_error_message( string &message)
{
	al_show_native_message_box(NULL, NULL, NULL, message.c_str(), NULL, ALLEGRO_MESSAGEBOX_ERROR);
}
